<script setup>
import { ref } from 'vue'

        const props = defineProps({
            imgUrl: {
                type: String,
                required: true,
                validator: value => {
                    if (value < 5) {
                        return false
                    }
                    return true
                }
            },
            title: {
                type: String,
                default: '商品标题'
            },
            price: {
                type: Number,
                required: true,
                validator: value => value >= 0 ? true : false
            },
            idx: {
                type: Number
            }
        })

        // const props = defineProps({
        //     age: Number,
        //     name: String,
        //     isActive: Boolean,
        //     callback: Function,
        //     list: Array,
        //     config: Object,
        // })
        const subNum = ref(3) 

        const emit = defineEmits()

        const onCut = () => {
            emit('onDiscount', props.idx, subNum.value)
        }
</script>
<template>
        <div class="item">
		<img
			:src="imgUrl"
			alt="展示失败" />
		<p class="name">{{ title }}</p>
		<p class="price">
			<span>{{ price }}</span>
			<button @click="onCut">砍一刀</button>
		</p>
	</div>
</template>

<style scoped lang="scss">
	.item {
		width: 240px;
		margin-left: 10px;
		padding: 20px 30px;
		transition: all 0.5s;
		margin-bottom: 20px;
		.item:nth-child(4n) {
			margin-left: 0;
		}

		&:hover {
			box-shadow: 0px 0px 5px rgba(0, 0, 0, 0.2);
			transform: translate3d(0, -4px, 0);
			cursor: pointer;
		}

		img {
			width: 100%;
		}

		.name {
			font-size: 18px;
			margin-bottom: 10px;
			color: #666;
		}

		.price {
			display: flex;
			align-items: center;
			height: 36px;
			font-size: 22px;
			color: firebrick;
			button {
				margin-left: 50px;
				font-size: 14px;
			}
		}

		.price::before {
			content: '¥';
			font-size: 22px;
		}
	}
</style>